﻿namespace Digitalmes.Core.Common.SerialPorts;

/// <summary>
/// 串口开关，用于开启或关闭指定的串口。
/// </summary>
public interface ISerialPortsSwitch
{
    /// <summary>
    /// 开启默认串口。
    /// </summary>
    /// <returns>是否成功开启</returns>
    /// <exception cref="NotFoundSerialPortException"></exception>
    /// <exception cref="PlatformNotSupportedException"></exception>
    /// <exception cref="FileNotFoundException"></exception>
    (bool ok, string? portName, Exception? ex) Open();

    /// <summary>
    /// 开启串口。
    /// </summary>
    /// <param name="portName">串口名称</param>
    /// <returns>是否成功开启</returns>
    /// <exception cref="NotFoundSerialPortException"></exception>
    /// <exception cref="PlatformNotSupportedException"></exception>
    /// <exception cref="FileNotFoundException"></exception>
    (bool ok, Exception? ex) Open(string portName);

    /// <summary>
    /// 通过用途开启串口。
    /// </summary>
    /// <param name="purpose">用途</param>
    /// <returns>是否成功开启</returns>
    /// <exception cref="NotFoundSerialPortException"></exception>
    /// <exception cref="PlatformNotSupportedException"></exception>
    /// <exception cref="FileNotFoundException"></exception>
    (bool ok, Exception? ex) OpenViaPurpose(string purpose);

    /// <summary>
    /// 关闭串口。
    /// </summary>
    /// <returns>是否成功关闭</returns>
    /// <exception cref="NotFoundSerialPortException"></exception>
    (bool ok, Exception? ex) Close();

    /// <summary>
    /// 关闭串口。
    /// </summary>
    /// <param name="portName">串口名称</param>
    /// <returns>是否成功关闭</returns>
    /// <exception cref="NotFoundSerialPortException"></exception>
    (bool ok, Exception? ex) Close(string portName);

    /// <summary>
    /// 通过用途关闭串口。
    /// </summary>
    /// <param name="purpose">用途</param>
    /// <returns>是否成功关闭</returns>
    /// <exception cref="NotFoundSerialPortException"></exception>
    (bool ok, Exception? ex) CloseViaPurpose(string purpose);
}
